package com.example.myproject.client;

import com.google.gwt.user.client.ui.Image;

/*************************************************************************
 * Class: Module
 * Purpose: Creates a Module
 * 
 * **********************************************************************/

public class Module {
	
	//CREATE VARIABLES
	
	//Configed-used to check if a module is configed
	private boolean configured;
	
	//modnum-a modules number
	//locX-a modules X location for the grid
	//locy-a modules Y location for the grid
	private int modNum, locX, locY, orient, prevX, prevY;	
	private String status, modType;
	
	/*************************************************************************
	 * Consructor for  a module class, takes in a num whihc is the module number
	 * 
	 * **********************************************************************/
	Module(int num)
	{		
		//instatiate grid coordinates to 1
		locX = 1;
		locY = 1;
		prevX = 0;
		prevY = 0;
		
		//modNum equals module number sent in
		modNum = num;
		
		//instatiate modules number of flips needed
		orient = 0;
		//instatiate modules current condition
		status = "Unknown";
		
		//instatiate modType
		modType = "Unknown";
		
		//set isConfiged to false
		configured = false;			
	}

	/*getModNum simply returns module num
	 * 
	 */
	public int getModNum(){ return modNum; }
	
	/*setX will take in a new x location
	 * 
	 */
	public void setX(int x){ locX = x; }
	
	/*getX will return the x location
	 * 
	 */
	public int getX(){ return locX; }
	
	/*setY will take in a new y location and set it
	 * 
	 */
	public void setY(int y){ locY = y; }
	
	/*getY will return the locaiton
	 * 
	 */
	public int getY(){ return locY; }
	
	/*setTempXY will set both x AND y, but will store a previous location
	 * as well incase of undoing a change made to them
	 */
	public void setTempXY(int x, int y)
	{
		prevX = locX;
		prevY = locY;
		
		locX = x;
		locY = y;
	}
	
	/*in contrast to set, this will 'reset' a location.  It will set x to prevX
	 * and y to prevY
	 */
	public void undoTempXY()
	{
		if(prevX != 0)
			locX = prevX;
		if(prevY != 0)
			locY = prevY;
	}
	
	/*Set the orientation for the module
	 * 
	 */
	public void setOrient(int num){ orient = num; }
	
	/* get the orientation for the module
	 * 
	 */
	public int getOrient(){ return orient; }
	
	/*set the status of a moduel
	 * 
	 */
	public void setStatus(String str){ status = str; }
	
	/*get the status of a module
	 * 
	 */
	public String getStatus(){ return status; }
		
	/*set the type of module
	 * 
	 */
	public void setModType(String str) { modType = str; }
	
	/* takes in a code for a module, and sets the type based on that code
	 * 
	 */
	public void setModType(int code)
	{		
		//if the number is less than 40, return a plain
		if(code <= 40)
			modType = "Plain";
		
		//if the number is less than 40, return a Dormatory
		else if( 41<=code && code<=80)
			modType =  "Dormitory";
		
		//if the number is less than 40, return a Sanitation
		else if( 91<=code && code<=100)
			modType =  "Sanitation";
		
		//if the number is less than 40, return a Food and Water Storage
		else if( 111<=code && code<=120)
			modType =  "Food and Water Storage";
		
		//if the number is less than 40, return a Gym
		else if( 131<=code && code<=134)
			modType = "Gym";
		
		//if the number is less than 40, return a Canteen
		else if( 141<=code && code<=144)
			modType = "Canteen";
		
		//if the number is less than 40, return a Power
		else if( 151<=code && code<=154)
			modType = "Power";
		
		//if the number is less than 40, return a Control
		else if( 161<=code && code<=164)
			modType = "Control";
		
		//if the number is less than 40, return a Airlock
		else if( 171<=code && code<=174)
			modType = "Airlock";
		
		//if the number is less than 40, return a Medical
		else if( 181<=code && code<=184)
			modType = "Medical";
	}
	
	/*gets the modules type
	 * 
	 */
	public String getModType(){ return modType; }
	
	/*set the configured flag to true
	 * 
	 */
	public void setConifigured(){ configured = true; }
	
	/*check if the configured flag is true
	 * 
	 */
	public boolean isConfigured(){ return configured; }
	
	/*checks the status for "undamaged" status.  if it is
	 * return true, else false
	 */
	public boolean checkStatus()
	{
		if(status.equals("undamaged"))
			return true;
		return false;
	}
	
	/*returns an image associated withe the module type
	 * 
	 */
	Image getImage()
	{		
		//if modtype is a plain, return the image associated with a plain
		if(modType.equals("Plain"))
			return new Image("images/plain.png");
		
		//if modtype is a Dormatory, return the image associated with a Dormatory
		else if(modType.equals("Dormitory"))
			return new Image("images/dorm.png");
		
		//if modtype is a Sanitation, return the image associated with a Sanitation
		else if(modType.equals("Sanitation"))
			return new Image("images/sanitation.png");	
		
		//if modtype is a food and water storage, return the image associated 
		//with a food and water storage
		else if(modType.equals("Food and Water Storage"))
			return new Image("images/store.png");
		
		//if modtype is a gym, return the image associated with a gym
		else if(modType.equals("Gym"))
			return new Image("images/gym.png");
		
		//if modtype is a canteen, return the image associated with a canteen
		else if(modType.equals("Canteen"))
			return new Image("images/food.png");
		
		//if modtype is a Power, return the image associated with a Power
		else if(modType.equals("Power"))
			return new Image("images/power.png");
		
		//if modtype is a Control, return the image associated with a Control
		else if(modType.equals("Control"))
			return new Image("images/control.png");
		
		//if modtype is an Airlock, return the image associated with an Airlock
		else if(modType.equals("Airlock"))
			return new Image("images/airlock.jpeg");
		
		//if modtype is a hospital, return the image associated with a hospital
		else
			return new Image("images/hosp.png");
	}

}

